package cn.xaut.XAUT迎春杯预热;

import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * O - 谁要的数据结构作业?
 */
public class demoO {

    public static void main(String[] args) {

        // 底层为小顶堆
        PriorityQueue<Long> pq = new PriorityQueue<Long>();

        Scanner input = new Scanner(System.in);
        long n = input.nextInt();
        for (long i = 0; i < n; i++) 
            pq.offer(input.nextLong());

        long sum = 0;
        while (pq.size() > 1) {
            long a = pq.poll();
            long b = pq.poll();
            long t = a + b;
            sum += t;
            pq.offer(t);
        }
        System.out.println(sum);
    }
}
